package com.ultimatech.servicesec;

import com.ultimatech.cloud.poc.base.model.TestData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by zhangleping on 2017/9/27.
 */
@SpringBootApplication
@EnableEurekaClient
@RestController
public class Service2App {

    public static void main(String[] args) {
        SpringApplication.run(Service2App.class, args);
    }

    @Value("${server.port}")
    private String port;

    @Value("${eureka.instance.hostname}")
    private String hostname;

    @RequestMapping("/hi")
    public String home(@RequestParam String name) {
        return "hi " + name + ",i am from :" + hostname + ":" + port;
    }

    @Value("${spring.application.name}")
    private String serviceName;

    @RequestMapping("/whoami")
    public String whoami(@RequestParam String name){
        return "Hi, "+name+" ! I'm Service "+this.serviceName+" on "+this.hostname;
    }

    @RequestMapping("/test")
    public TestData test(@RequestParam String name) {
        TestData testData = new TestData();
        testData.setId(1234);
        testData.setName(name);
        testData.setCreateData(new Date());
        return testData;
    }

}
